package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {
    @Select("select count(*) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    @Select("select s.*, c.name categoryName from setmeal s, category c " +
            "where s.id = #{id} and s.category_id = c.id")
    SetmealVO selectByIdWithCategoryName(Integer id);

    @AutoFill(value = OperationType.INSERT)
    void insert(Setmeal setmeal);

    void deleteByIds(List<Long> ids);

    @AutoFill(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    @Select("select * from setmeal where id = #{id}")
    Setmeal selectById(Long id);

    @Select("select * from setmeal where category_id = #{categoryId}")
    List<Setmeal> selectByCategoryId(Long categoryId);

    @Select("select setmeal_dish.name, setmeal_dish.copies, dish.image, dish.description" +
            " from setmeal_dish, dish " +
            "where setmeal_dish.setmeal_id = #{id} and setmeal_dish.dish_id = dish.id")
    List<DishItemVO> getDishItemById(Long id);
    @Select("select count(*) from setmeal where status = #{status}")
    Integer countByStatus(Integer status);
}
